import { ApiProperty } from "@nestjs/swagger";
import { IsBoolean, IsNumber, IsString, MaxLength } from "class-validator";
import { PhotoMetadata } from "libs/db/entity/photoMetadata.entity";
import { Column, OneToOne, PrimaryGeneratedColumn } from "typeorm";

export class ReplacePhotoDto {
  @ApiProperty({
    description: 'number',
    required: false
  })
  @PrimaryGeneratedColumn()
  id?: number;

  @ApiProperty({
    example: 'haha',
    description: '名字',
    required: true
  })
  @IsString()
  @Column({
    type: "varchar"
  })
  name: string;


  @ApiProperty({
    example: '我是 一条说明',
    description: '最大长度为 2',
    required: true
  })
  @MaxLength(2, { always: true, message: _ => `${_.targetName} 中的 ${_.property} 最大长度 应为 ${_.constraints[0]}` })
  @IsString()
  @Column()
  description: string;

  @ApiProperty({
    example: 'hahah',
    description: '文件名字 ',
    required: false
  })
  @IsString()
  @Column()
  filename: string;


  @ApiProperty({
    example: 1,
    description: '文件大小 ',
    required: false
  })
  @IsNumber()
  @Column()
  views: number;

  @ApiProperty({
    example: true,
    description: '是否公开 ',
    required: false
  })
  @IsBoolean()
  @Column()
  isPublished: boolean;

  @ApiProperty({
    example: new PhotoMetadata(),
    description: '照片信息对象',
    required: false,
    type: [PhotoMetadata]
  })
  @OneToOne(() => PhotoMetadata, photoMetadata => photoMetadata.photo, {
    lazy: true
  })
  metadata: PhotoMetadata;
}